<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .oul {
            display: flex;
            text-align: center;
            line-height: 46px;
        }

        li {
            flex: 1;
        }

        .box {
            text-align: center;
            line-height: 200px;
            font-size: 26px;
        }

        .active {
            background: orange;
            color: #fff;
        }
    </style>
</head>

<body>

    <div id="app">
        <ul class="oul">
            <!-- 0 -->
            <!-- 1 -->
            <!-- 2 -->

            <!-- 1. 通过v-for循环出来   2. 绑定了事件 -->
            <li v-for="(item, index) in list"
                :class="index === count? 'active': ''"
                @click="changeIndex(index)"
                >
                {{ item }}
            </li>

            <!-- <li v-for="(item, index) in list" :class="{
                active: index === count
            }" @click="changeIndex(index)">
                {{ item }}
            </li> -->
        </ul>
        <div class="box">
            {{ list[count] }}
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>

        new Vue({
            // 元素
            el: "#app",
            // 定义的数据(状态)
            data: {
                // 当前选中的状态
                count: 0,
                list: ["语文", "数学", "英语"]
            },
            methods: {
                changeIndex(index) {
                    this.count = index
                    console.log(index)
                }
            }
        })
    </script>
</body>

</html>